package com.lanou.musicbox.activity;

import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import com.lanou.musicbox.R;
import com.lanou.musicbox.base.BaseActivity;


/**
 * Created by 杨海宁 on 15/10/27.
 * videoView 播放视频
 *
 */
public class VideoVIewActivity extends BaseActivity{
    private VideoView videoView;
    MediaController mediaController;
    private String video_url ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        videoView  = (VideoView) findViewById(R.id.video_view);
        mediaController = new MediaController(this);
       video_url =  getIntent().getExtras().getString("video_url");
        Log.i("lanou66666666", "onCreate "+ video_url);
        Uri uri = Uri.parse (video_url);


        if (video_url!=null){
            videoView.setMediaController(mediaController);
            videoView.setVideoURI(uri);
            videoView.requestFocus();
        }

    }

    /**
     * 判断横竖屏的状态
     * @param newConfig
     */
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        // TODO Auto-generated method stub         super.onConfigurationChanged(newConfig);
        if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE )
        {
            Toast.makeText(getApplicationContext(), "切换为横屏", Toast.LENGTH_SHORT).show();
        }else if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {
            Toast.makeText(getApplicationContext(), "切换为竖屏", Toast.LENGTH_SHORT).show();
        }
    }
}
